import '../style/init.css'
import websocket from "@/js/websocket";


export let cmdChannel;

let httpProtocol = 'http'
let wsProtocol = 'ws'
// 用于本地调试
const webPort = 8002;

function doMobileStart() {
    let availWidth = screen.availWidth;
    document.body.style.setProperty("--availWidth", availWidth + "px");
}

function doPcStart() {
    let body = document.body;
    let isDark = localStorage.getItem('arco-theme-dark');
    if (isDark !== '0') {
        body.setAttribute('arco-theme', 'dark');
    }
    let availHeight = screen.availHeight * 0.99;
    body.style.setProperty("--availHeight", availHeight + "px");
}

export function init() {


    let isMobile = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i);
    if (isMobile) {
        doMobileStart();

    } else {
        doPcStart();
    }

    if (document.location.protocol === 'https') {
        httpProtocol = 'https'
        wsProtocol = 'wss'
    }
    if (process.env.NODE_ENV === 'development') {
        window.dev = {
            httpUrlBase: httpProtocol + '://' + location.hostname + ':' + webPort
        };
        window.wsUrlBase = wsProtocol + '://' + location.hostname + ':' + webPort;
    } else {
        window.wsUrlBase = wsProtocol + '://' + location.hostname + ':' + location.port;
    }


    cmdChannel = new websocket('/control');


}